const getCookieToken = async() => { // 获取本地存储在cookie中的token
    const cookieArr = document.cookie.split(";")
    const refreshTokenObj = cookieArr.find(item => item.indexOf('refreshToken') > -1)
    const refreshToken = refreshTokenObj && refreshTokenObj.replace("refreshToken=","").trim()

    const accessTokenObj = cookieArr.find(item => item.indexOf('accessToken') > -1)
    const accessToken = accessTokenObj && accessTokenObj.replace("accessToken=","").trim()

    const redirectUriObj = cookieArr.find(item => item.indexOf('redirectUri') > -1)
    const redirectUri = redirectUriObj && redirectUriObj.replace("redirectUri=","").trim()
    return { refreshToken, accessToken, redirectUri }
}
const setCookieToken = async() => { // cookie 存储token
    // const refreshTokenDate = new Date()
    // const accessTokenDate = new Date() 
    // let refreshTokenTime = 1000 * 60 * 60 * 24 * 30// refreshToken cookie的有效期暂定一个月为30天
    // let accessTokenTime = 1000 * 60 * 60 * 2// accessToken cookie的有效期暂定为2个小时
    // refreshTokenTime = refreshTokenDate.getTime() + refreshTokenTime
    // accessTokenTime = accessTokenDate.getTime() + accessTokenTime

    // refreshTokenDate.setTime(refreshTokenTime)
    // accessTokenDate.setTime(accessTokenTime)
    // const refreshToken = sessionStorage.getItem('refreshToken')
    // const accessToken = sessionStorage.getItem('accessToken')
    // // let refreshToken = sessionStorage.getItem('refreshToken')
    // if(refreshToken) {
    //     document.cookie = `refreshToken=${refreshToken};expires=${refreshTokenDate.toUTCString()};path=/`
    // }
    // if(accessToken) {
    //     document.cookie = `accessToken=${accessToken};expires=${accessTokenDate.toUTCString()};path=/`
    // }
   
    // document.cookie = `redirectUri=${url};expires=${accessTokenDate.toUTCString()};path=/`
}
const clearCookieToken = () => {
    sessionStorage.clear()
    document.cookie = "refreshToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"
    document.cookie = "accessToken=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"
    document.cookie = "redirectUri=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"
}
export { getCookieToken, setCookieToken, clearCookieToken }
